import logging
from datetime import timedelta

from redis import StrictRedis


# 设置配置信息
class Config(object):
    # 调试信息
    DEBUG = True
    SECRET_KEY = "1234"

    # 数据库信息
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:123456@localhost:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # redis配置信息
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # session配置信息
    SESSION_TYPE = "redis"
    SESSION_REDIS = StrictRedis(REDIS_HOST, REDIS_PORT)  # 指定session存储的服务器
    SESSION_SIGNER = True  # 设置签名加密
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)

    # 默认日志级别
    LEVEL_NAME = logging.DEBUG

# 开发环境配置信息
class DevelopConfig(Config):
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:123456@localhost:3306/information"
    LEVEL_NAME = logging.DEBUG

# 生产环境配置信息
class ProductConfig(Config):
    DEBUG = False
    LEVEL_NAME = logging.ERROR

# 测试环境配置信息
class TestConfig(Config):
    pass


# 提供一个统一入口
config_dict = {
    "develop": DevelopConfig,
    "product": ProductConfig,
    "test": TestConfig
}
